﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utilities
{
    public class DateTimeUtils
    {
        public static DateTime LastDay(DateTime dateTime, DayOfWeek dayOfWeek)
        {
            while (dateTime.DayOfWeek != dayOfWeek)
                dateTime = dateTime.AddDays(-1);
            return dateTime.AddHours(-dateTime.Hour).AddMinutes(-dateTime.Minute).AddSeconds(-dateTime.Second).AddMilliseconds(-dateTime.Millisecond).AddTicks(-dateTime.Millisecond);
        }
        public static DateTime NextDay(DateTime dateTime, DayOfWeek dayOfWeek)
        {
            while (dateTime.DayOfWeek != dayOfWeek)
                dateTime = dateTime.AddDays(1);
            return dateTime.AddHours(-dateTime.Hour).AddMinutes(-dateTime.Minute).AddSeconds(-dateTime.Second).AddMilliseconds(-dateTime.Millisecond).AddTicks(-dateTime.Millisecond);
        }
    }

    public static class DateTimeExtension
    {
        public static DateTime NextDay(this DateTime dateTime, DayOfWeek dayOfWeek)
        {
            while (dateTime.DayOfWeek != dayOfWeek)
                dateTime = dateTime.AddDays(1);
            return dateTime.Date;
        }
    }
}
